package com.yunkuhui.www.demo.controller;

import com.yunkuhui.www.demo.form.AssetIndex;
import com.yunkuhui.www.demo.model.TestUser;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/redis")
public class RedisController {

	@Resource(name = "redisTemplate0")
	private RedisTemplate redisTemplate0;

	@RequestMapping("/1")
	@SuppressWarnings("unchecked")
	public Object testAddRedisData() {
		Map<String, String> map = new HashMap<>();
		map.put("a", "发顺丰");
		map.put("b", "纳瑟健康");
		map.put("c", "大法官博客发表");
		map.put("d", "大杯咖啡");
		map.put("e", "宫颈癌白金卡");
		ValueOperations valueOperations = redisTemplate0.opsForValue();
		valueOperations.set("1", map);
		return valueOperations.get("1");
	}

	@RequestMapping("/2")
	@SuppressWarnings("unchecked")
	public Object testAddRedisData1() {
		AssetIndex assetIndex = new AssetIndex();
		assetIndex.setContract("a");
		assetIndex.setInvoice("b");
		ValueOperations valueOperations = redisTemplate0.opsForValue();
		valueOperations.set("2", assetIndex);
		return valueOperations.get("2");
	}

	@RequestMapping("/3")
	@SuppressWarnings("unchecked")
	public Object testAddRedisData3() {
		TestUser testUser = new TestUser();
		testUser.setUserName("userName1");
		testUser.setUserSex("m");
		testUser.setUserEmail("leiyunran@qq.com");
		testUser.setUserBirthday(new Date());
		ValueOperations valueOperations = redisTemplate0.opsForValue();
		valueOperations.set("3", testUser);
		return valueOperations.get("3");
	}
}
